<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
	String studentno = null;
	if (null != request.getAttribute("studentno")) {
		studentno = (String) request.getAttribute("studentno");
	}
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>学生信息查询</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<link rel="stylesheet"
			href="<%=request.getContextPath()%>/css/common.css" type="text/css" />

		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/interface/dWRCollegeMajorAction.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/interface/studentAction.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/engine.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/util.js'></script>
		<script type="text/javascript"
			src="<%=request.getContextPath()%>/js/N13FormValidation-2.js"></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/js/checkform.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/js/commonValidate.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/js/jquery-latest.pack.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/js/noConflictOfJquery.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/js/forCSS.js'></script>
		<script type='text/javascript'>
		
	if(null != <%=studentno%>){
		alert('修改成功!');
	}
	
	//全局变量
	var totalcount = -1;
	var page;   //dwr分页的page对象，注意在页面中是一个Json对象
	var seleFlag ; //标记选择是学号还是姓名 ,0为学号,1为姓名
	
	//查询满足条件的学生的总数回调函数
	var searchStudentTotalRowsCallback = function searchStudentTotalRowsCallbackFunc(count){
		if(count == 0){
			alert("没有此学生的信息");
			return;
		}
		totalcount = count;
		if(seleFlag == 0){
			studentAction.searchStudentByStudentDimNo($('studentForSearch').value, 1,totalcount,getStudentInfoCallback);
		}else{
			studentAction.searchStudentByStudentName($('studentForSearch').value,1,totalcount,getStudentInfoCallback);
		}
	}
	
	//先查询要分页的总行数
    var getStudentInfoCallback = function getStudentInfoCallbackFunc(sl){
    	//如果没有重名的学生就直接显示
		//如果有多个学生就先显示列表
		//sl是学生列表
		if(sl == null){
			alert("没有该学生的信息!");
			return;
		}
    	if(sl.length == 1){
    			studentAction.searchStudentByStudentNo(sl[0].studentno,searchStudentByStudentNoCallback);
    	}else{
    		$("slTable").style.display = '';
	        if($('slTable').style.visibility == 'visible'){
	            $('slTable').style.visibility = 'hidden';
	        }
	        if($('pageTable').style.visibility == 'hidden'){
	            $('pageTable').style.visibility = 'visible';
	        }
	        DWRUtil.removeAllRows('ttb', { filter:function(tr) {
	              return (tr.id != "pattern");
	                }});
	        var al,id;
			for (var i =0; i < sl.length ; i++) {
			     al = sl[i];
			     id = al.studentid;
			     dwr.util.cloneNode("pattern", { idSuffix:id });
			     dwr.util.setValue("stuName"+id, al.studentname);
			     dwr.util.setValue("stuNo"+id, al.studentno);
			     dwr.util.setValue("stuGender"+id, al.studentgender);
			     dwr.util.setValue("stuDetail"+id,"查看详情");
			     $("pattern" + id).style.display= "";
			}
			setPageInfo(); //这里写页面信息
	         tbCSS();
	             //这里是奇偶行不一致的css写法
	        /*
			var Ptr= document.getElementById('slTable').getElementsByTagName('tr'); 
			for (i=1;i<Ptr.length+1;i++) {
			  Ptr[i-1].className = (i%2>0)?"row_odd":"row_even";
			}   
			*/
	    }          
    }
    
	//单击‘详细信息’查看学生详细信息
	//num是动态表格slTable的行号
	function getStudentInfoDetail(obj){
		var num = obj.id.substr(7);
		studentAction.searchStudentByStudentNo($('stuNo'+num).innerHTML,searchStudentByStudentNoCallback);
	}
	function getStudentInfo(){
		
		var stu = strTrim_cv($('studentForSearch').value);
		if(stu == ""){
				alert("输入不能为空！");
				return ;
		}
		if(!cnChar_cv(stu)){
				alert("您只能输入数字,字母和汉字,请重新输入");
				return;
		}
		
    	//判断搜索条件是选中的了学号还是选中姓名
    	//todo
		if($('searchType').options[$('searchType').selectedIndex].value == "stuno"){
			seleFlag = 0;
			studentAction.searchStudentByStudentDimNoTotalRows(stu ,searchStudentTotalRowsCallback);
		}else{
			seleFlag = 1;
			studentAction.searchStudentByStudentNameTotalRows(stu ,searchStudentTotalRowsCallback);
			
		}
	}
	//通过学号查询学生的回调函数，一般是在模糊查询的结果集中点选某人时根据学号查出
	var searchStudentByStudentNoCallback = function searchStudentByStudentNoCallbackFunc(sl){
		var s = eval('(' + sl + ')');//JSON
		$('studentid').value = s.studentid;
		$('studentno').value = s.studentno;
		$('studentpicture').src="/dms"+s.studentpicturepath;
		$('studentpassword').value = s.studentpassword ;
		$('studentname').value = s.studentname ;
		if($('studentgenderMale').value == s.studentgender){
			$('studentgenderMale').checked="checked";	
		}else{
			$('studentgenderFemale').checked="checked";
		}
		$('studentbirthday').value = s.studentbirthday;
		$('studentidentitycardno').value = s.studentidentitycardno;
		$('studentbirthplace').value = s.studentbirthplace ;
		$('studentethnic').value = s.studentethnic ;
		for(var a = 0;a<$('studenttype').options.length;a++){
			if($('studenttype').options[a].value == s.studenttype){
				$('studenttype').options[a].selected = "selected";
			}
		}
		
		for(var a = 0;a<$('studentenrolltype').options.length;a++){
			if($('studentenrolltype').options[a].value == s.studentenrolltype){
				$('studentenrolltype').options[a].selected = "selected";
			}
		}
		for(var a = 0;a<$('studenteducationyears').options.length;a++){
			if($('studenteducationyears').options[a].value == s.studenteducationyears){
				$('studenteducationyears').options[a].selected = "selected";
			}
		}
		for(var a = 0;a<$('studentadmissiontype').options.length;a++){
			if($('studentadmissiontype').options[a].value == s.studentadmissiontype){
				$('studentadmissiontype').options[a].selected = "selected";
			}
		}
		for(var a = 0;a<$('studentenrollyear').options.length;a++){
			if($('studentenrollyear').options[a].value == s.studentenrollyear){
				$('studentenrollyear').options[a].selected = "selected";
			}
		}
		$('studenttelephone').value = s.studenttelephone ;
		$('studenthomeaddress').value = s.studenthomeaddress ;
		$('studentarchivesaddress').value = s. studentarchivesaddress;
		$('studentmisc').value = s.studentmisc;
		
		$('complexSearch').style.display = "";	
	}
	//点“开始编辑”触发的事件
	function startEdit(obj){
		var   a=document.getElementsByTagName("input");  
       	for(var i=0;i<a.length;i++){  
             if(a[i].disabled == true){
             		a[i].disabled = false;
             }
        } 
        var b=document.getElementsByTagName("select");  
       	for(var i=0;i<b.length;i++){  
             if(b[i].disabled == true){
             		b[i].disabled = false;
             }
        } 
        $('submitBtn').disabled = false;
        obj.disabled = true;
        
	}
	//提交编辑结果
	function submitEdit(obj){
		//$('submitBtn').disabled = true;
       // obj.disabled = false;
        $('stuForm').submit();
	}
	//删除记录
	function deleteRecord(obj){
		if(!confirm("确定删除?")){
			return;
		}
		var si = $('studentid').value;
		studentAction.deleteStudent(si,deleteStudentCallback);
	}
	//删除记录回调函数
	var deleteStudentCallback = function deleteStudentCallbackFunc(returnString){
		if(returnString == "success"){
			alert("删除成功!");
			window.location.reload();
		}
		else{
			alert("删除失败!!");
		}
	}
	//enter键按下提交搜索
 	function subit(eventTag){
	 	var event = eventTag||window.event;    
   		var currentKey = event.charCode||event.which;  
			if(currentKey==13){ 
				getStudentInfo(); 
			}
	} 
	document.onkeydown = subit;
	
	
	


    
    function setPageInfo(){
        $('pageTd').innerHTML = '';
        $('pageSelect').style.display = 'none';
        studentAction.getPage({  //调用action层getPage()方法
            callback:function(data){
                page = data;
                //显示 当前页/总页数
                if(page.totalPage != 0){
                    var pageSpan = document.createElement('span');
                    pageSpan.innerHTML = page.currentPage + '/' + page.totalPage;
                    $('pageTd').appendChild(pageSpan);
                }
                //显示 首页 前一页
                if(page.currentPage > 1){
                    var aFirst = document.createElement('a');
                    aFirst.setAttribute('href','javascript:getFirstData()');
                    aFirst.innerHTML = '首页';
                    $('pageTd').appendChild(aFirst);
                    var aPrevious = document.createElement('a');
                    aPrevious.setAttribute('href','javascript:getPreviousData()');
                    aPrevious.innerHTML = '前一页';
                    $('pageTd').appendChild(aPrevious);
                }
                //显示 下一页 末页
                if(page.currentPage < page.totalPage){
                    var aNext = document.createElement('a');
                    aNext.setAttribute('href','javascript:getNextData()');
                    aNext.innerHTML = '下一页';
                    $('pageTd').appendChild(aNext);
                    var aLast = document.createElement('a');
                    aLast.setAttribute('href','javascript:getLastData()');
                    aLast.innerHTML = '末页';
                    $('pageTd').appendChild(aLast);
                }
                //显示下拉框
             
                if(page.totalPage != 1){
                    $('pageSelect').innerHTML = '';
                    $('pageSelect').style.display = '';
                    for(var i=1; i<=page.totalPage; i++){
                        var option = document.createElement('option');
                        option.setAttribute('value', i);
                        if(i == page.currentPage){
                            option.setAttribute('selected', 'selected');
                        }
                        option.innerHTML = i;
                        $('pageSelect').appendChild(option);
                    }
                }
            }
        });
        $('loading').style.display = 'none';
    }

    function getFirstData(){
        page.currentPage = 1;
        getDataPerPage();
    }
    
    function getPreviousData(){
        page.currentPage--;
        getDataPerPage();
    }
    
    function getNextData(){
        page.currentPage++;
        getDataPerPage();
    }
    
    function getLastData(){
        page.currentPage = page.totalPage;
        getDataPerPage();
    }
    
    function gotoPage(select){
        page.currentPage = select.options[select.selectedIndex].value;
        getDataPerPage();
    }
    
    
    function getDataPerPage(){
        $('loading').style.display = '';
        //调用方法
        if(seleFlag == 0){
			studentAction.searchStudentByStudentDimNo($('studentForSearch').value,page.currentPage,totalcount,getStudentInfoCallback);
		}else{
			studentAction.searchStudentByStudentName($('studentForSearch').value,page.currentPage,totalcount,getStudentInfoCallback);
		}
    }    
	//enter键按下提交搜索
  
  function   subEv(event)   {  
	  event = event ? event : (window.event ? window.event : null);    
	  if(event.keyCode==13) {
	  	 getStudentInfo();
	  }
   
  } 
  document.onkeydown=subEv;
	</script>
	</head>

	<body>
		<div id="page_container">
			<jsp:include page="studentsearchnav.jsp"></jsp:include>
			<h2>
				搜索学生
			</h2>
			<div id="basicSearch">
				<form id="stuForm" action="student/updatestudent.action"
					method="post">
					<select class="common_select" id="searchType" 　name="searchType">
						<option value="stuno">
							学号
						</option>
						<option value="stuname">
							姓名
						</option>
					</select>
					<input type="text" name="studentForSearch" id="studentForSearch"
						value="" />

					<input class="common_button" type="button" value="搜索" onclick="getStudentInfo()" />
			</div>

			<span> <!-- 显示通过姓名查询出学生列表，因可能存在重名 -->
				<div>
					<table id="slTable" style="display: none;" class="table_list_style">
						<thead>
							<tr>
								<th>
									姓名
								</th>
								<th>
									学号
								</th>
								<th>
									性别
								</th>
								<th>
									链接
								</th>
							</tr>
						</thead>
						<tbody id="ttb">
							<tr id="pattern" style="display: none;"
								onclick='getStudentInfoDetail(this)'>
								<td width="80px">
									<span id="stuName"></span>
								</td>
								<td width="80px">
									<span id="stuNo"></span>
								</td>
								<td width="35px">
									<span id="stuGender"></span>
								</td>
								<td width="120px">
									<a id='stuDetail'>详细信息</a>
								</td>
							</tr>
						</tbody>
					</table>
				</div>

				<table id="pageTable" align="center"
					style="visibility: hidden; margin-top: 30px; font: 12px;">
					<tr>
						<td id="pageTd"></td>
						<td>
							<select id="pageSelect" onchange="gotoPage(this);"></select>
						</td>
					</tr>
				</table>
				<div id="loading"
					style="display: none; margin-top: 20px; text-align: center; color: red; font: 13px;">
					Loading...
				</div> </span>





			<div id="complexSearch" style="display: none">

				<table class="table_common">
					<tr>
						<td>

							<br>
							<br>
						</td>
						<td>
							<input type="hidden" name="student.studentid" id="studentid" />
							<br>
							<br>
							<br>
							<br>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							学号：
							<br>
							<br>
						</td>
						<td class="td_right">
							<input type="text" name="student.studentno" id="studentno"
								disabled=true />
							<br>
							<br>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							照片：
							<br>
							<br>
						</td>
						<td class="td_right">
							<img id="studentpicture" src="<%=request.getContextPath()%>"
								width="75px" height="100px" />
							<br>
							<br>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							密码：
							<br>
							<br>
							<br>
							<br>
						</td>
						<td class="td_right">
							<input type="text" name="student.studentpassword"
								id="studentpassword" disabled=true />
							<br>
							<br>
							<br>
							<br>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							姓名：
							<br>
							<br>
							<br>
							<br>
						</td>
						<td class="td_right">
							<input type="text" name="student.studentname" id="studentname"
								disabled=true />
							<br>
							<br>
							<br>
							<br>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							性别：
							<br>
							<br>
							<br>
							<br>
						</td>
						<td class="td_right">
							<input id="studentgenderMale" type="radio" value="男"
								name="student.studentgender" disabled=true />
							男
							<input id="studentgenderFemale" type="radio" value="女"
								name="student.studentgender" disabled=true />
							女
							<br>
							<br>
							<br>
							<br>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							出生日期：
							<br>
							<br>
							<br>
							<br>
						</td>
						<td class="td_right">
							<input type="text" name="student.studentbirthday"
								id="studentbirthday" disabled=true />
							<br>
							<br>
							<br>
							<br>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							身份证号：
							<br>
							<br>
							<br>
							<br>
						</td>
						<td class="td_right">
							<input type="text" name="student.studentidentitycardno"
								id="studentidentitycardno" disabled=true />
							<br>
							<br>
							<br>
							<br>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							生源地：
							<br>
							<br>
							<br>
							<br>
						</td>
						<td class="td_right">
							<input type="text" name="student.studentbirthplace"
								id="studentbirthplace" disabled=true />
							<br>
							<br>
							<br>
							<br>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							民族：
							<br>
							<br>
							<br>
							<br>
						</td>
						<td class="td_right">
							<input type="text" name="student.studentethnic"
								id="studentethnic" disabled=true />
							<br>
							<br>
							<br>
							<br>
					</tr>
					<tr>
						<td class="td_left">
							学生类型：
							<br>
							<br>
							<br>
							<br>
						</td>
						<td class="td_right">
							<select id="studenttype" name="student.studenttype"
								disabled="true">
								<option value="">

								</option>
								<option value="预科">
									预科
								</option>
								<option value="本科">
									本科
								</option>
								<option value="硕士研究生">
									硕士研究生
								</option>
								<option value="博士研究生">
									博士研究生
								</option>
								<option value="博士后">
									博士后
								</option>
							</select>
							<br>
							<br>
							<br>
							<br>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							招生类别：
							<br>
							<br>
							<br>
							<br>
						</td>
						<td class="td_right">
							<select id="studentenrolltype" name="student.studentenrolltype"
								disabled="true">
								<option value="">

								</option>
								<option value="预科">
									预科
								</option>
								<option value="本科">
									本科
								</option>
								<option value="硕士研究生">
									硕士研究生
								</option>
								<option value="博士研究生">
									博士研究生
								</option>
								<option value="博士后">
									博士后
								</option>
							</select>
							<br>
							<br>
							<br>
							<br>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							学制：
							<br>
							<br>
							<br>
							<br>
						</td>
						<td class="td_right">
							<select id="studenteducationyears"
								name="student.studenteducationyears" disabled="true">
								<option value="">

								</option>
								<option value="4">
									四年
								</option>
								<option value="2.5">
									两年半
								</option>
								<option value="2">
									两年
								</option>
								<option value="3">
									三年
								</option>
							</select>
							<br>
							<br>
							<br>
							<br>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							录取类别：
							<br>
							<br>
							<br>
							<br>
						</td>
						<td class="td_right">
							<select id="studentadmissiontype"
								name="student.studentadmissiontype" disabled="true">
								<option value="">

								</option>
								<option value="预科">
									预科
								</option>
								<option value="本科">
									本科
								</option>
								<option value="硕士研究生">
									硕士研究生
								</option>
								<option value="博士研究生">
									博士研究生
								</option>
								<option value="博士后">
									博士后
								</option>
							</select>
							<br>
							<br>
							<br>
							<br>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							入学年份：
							<br>
							<br>
							<br>
							<br>
						</td>
						<td class="td_right">
							<select id="studentenrollyear" name="student.studentenrollyear"
								disabled="true">
								<option value="">

								</option>
								<option value="2003">
									03年
								</option>
								<option value="2004">
									04年
								</option>
								<option value="2005">
									05年
								</option>
								<option value="2006">
									06年
								</option>
								<option value="2007">
									07年
								</option>
								<option value="2008">
									08年
								</option>
								<option value="2009">
									09年
								</option>
							</select>
							<br>
							<br>
							<br>
							<br>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							联系电话：
							<br>
							<br>
							<br>
							<br>
						</td>
						<td class="td_right">
							<input id="studenttelephone" type="text" value=""
								name="student.studenttelephone" disabled=true />
							<br>
							<br>
							<br>
							<br>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							通信地址：
							<br>
							<br>
							<br>
							<br>
						</td>
						<td>
							<input id="studenthomeaddress" type="text" value=""
								name="student.studenthomeaddress" disabled=true />
							<br>
							<br>
							<br>
							<br>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							档案所在地：
							<br>
							<br>
							<br>
							<br>
						</td>
						<td class="td_right">
							<input id="studentarchivesaddress" type="text" value=""
								name="student.studentarchivesaddress" disabled=true />
							<br>
							<br>
							<br>
							<br>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							备注：
							<br>
							<br>
							<br>
							<br>
						</td>
						<td class="td_right">
							<input id="studentmisc" type="text" value=""
								name="student.studentmisc" disabled=true />
							<br>
							<br>
							<br>
							<br>
						</td>
					</tr>
					<tr>
						<td>
							<input type="button" value="开始编辑" onclick="startEdit(this)" />
							<input id="submitBtn" type="button" value="提交修改"
								onclick="submitEdit(this)" disabled=true />
							<input id="deleteBtn" type="button" value="删除"
								onclick="deleteRecord(this)" disabled=true />
							<br>
							<br>
						</td>
				</table>
			</div>
		</div>
		<script type="text/javascript">
			N13.register('stuForm',[
					{
						id:'studentname',
						type:'Required', 
						validMsg:'√',
						validOnBlur:true,
						renderValid:true
					},
					{
						id:'studentbirthday',
						type:'format',
						validMsg:'√',
						validOnBlur:true,
						renderValid:true,
						pattern: /^(\d{4})-(0\d{1}|1[0-2])-(0\d{1}|[12]\d{1}|3[01])$/i
					},
					{
						id:'studentidentitycardno',
						type:'Required',
						validMsg:'√',
						validOnBlur:true,
						renderValid:true
					},
					{
						id:'studentethnic',
						type:'Required',
						validMsg:'√',
						validOnBlur:true,
						renderValid:true
					}
					
				]);
		//当提交修改返回的时候自动重查并赋值
		//function submitReturn(){
		
			//if(null != <%=request.getAttribute("studentForSearch")%>){　　
			//	$('studentForSearch').value = '<%=request.getAttribute("studentForSearch")%>';
			//	if('<%=request.getAttribute("searchType")%>' == 'stuno'){     //表明之前是用学号搜索的
				//	$('searchType').options[0] = "selected";
				//}else $('searchType').options[1] = "selected";               //之前是用姓名搜索的
				//alert("to");
				//studentAction.searchStudentByStudentNo($('studentForSearch').value,getStudentInfoCallback);
			//} 
		//}
		//submitReturn();
		</script>
	</body>
</html>
